﻿@inject AppConfiguration appConfiguration
@{
    var menuList = (ViewData["menuList"] as List<Dictionary<string, object>>)??new List<Dictionary<string,object>>();
}
@model string
@functions{

    void CreateMenu(List<Dictionary<string, object>> menus)
    {
        //
        foreach (var item in menus)
        {
            var id = item["id"];
            var title = item["name"];
            var href = item["path"];
            var icon = item["icon"];
            var isClose = item["isClose"];
            var childless = item["children"] as List<Dictionary<string, object>>;
            if (childless == null) continue;
            if (childless.Count > 0)
            {
                <el-submenu index="@(id)">

                    <template slot="title">
                        <i class="@icon"></i>
                        <span slot="title">@(title)</span>
                    </template>

                   @{CreateMenu(childless);}
                    
                </el-submenu>
            }
            else
            {
                <el-menu-item index="@(id)">
                    <i class="@icon"></i>
                    <span slot="title">@(title)</span>
                </el-menu-item>
            }
        }
    }

    //void CreateMenu(List<Dictionary<string, object>> menus)
    //{
        
    //    foreach (var item in menus)
    //    {
    //        var id = item["id"];
    //        var title = item["name"];
    //        var href = item["path"];
    //        var icon = item["icon"];
    //        var isClose = item["isClose"];
    //        var childless = item["children"] as List<Dictionary<string, object>>;
    //        if (childless == null) continue;
    //        if (childless.Count > 0)
    //        {
    //            <el-submenu index="@(id)">

    //                <template slot="title">
    //                    <i class="@icon"></i>
    //                    <span slot="title">@(title)</span>
    //                </template>

    //               @foreach (var children in childless)
    //                {
    //                    id = children["id"];
    //                    title = children["name"];
    //                    href = children["path"];
    //                    icon = children["icon"];
    //                    isClose = children["isClose"];
    //                    childless = children["children"] as List<Dictionary<string, object>>;
    //                    if (childless == null) continue;
    //                    if (childless.Count > 0)
    //                    {
    //                        var menu = new List<Dictionary<string, object>>();
    //                        menu.Add(children);
    //                        CreateMenu(menu);
    //                    }
    //                    else
    //                    {
    //                        <el-menu-item index="@(id)">
    //                            <i class="@icon"></i>
    //                            <span slot="title">@(title)</span>
    //                        </el-menu-item>
    //                    }
    //                }
                    
    //            </el-submenu>
    //        }
    //        else
    //        {
    //            <el-menu-item index="@(id)">
    //                <i class="@icon"></i>
    //                <span slot="title">@(title)</span>
    //            </el-menu-item>
    //        }
    //    }
    //}

}
<div class="hzy-admin-logo">@(appConfiguration.Configs.AppTitle)</div>

@if (Model == "pc")
{
    <!--menu 菜单-->
    <el-menu :default-active="activeMenuKey" @@select="handleMenuSelect" :collapse="isCollapse" :background-color="menuTheme.backgroundColor" :text-color="menuTheme.textColor" :active-text-color="menuTheme.activeTextColor">
        @{CreateMenu(menuList);}
    </el-menu>
}
else
{
    <!--menu 菜单-->
    <el-menu :default-active="activeMenuKey" @@select="handleMenuSelect" :background-color="menuTheme.backgroundColor" :text-color="menuTheme.textColor" :active-text-color="menuTheme.activeTextColor">
        @{CreateMenu(menuList);}
    </el-menu>
}
